package micro.beauty.common.mvc.wrapper;


import java.io.PrintWriter;

/**
 * @Description: PrintWriter是一种写入字符的一种操作类，可以写入字符，TeePrintWriter继承了他，主要功能是把原始的字符流copy到branch里面。
 * @Author: liuliya
 * @CreateDate: 2020/4/29 13:20
 * @see org.apache.commons.io.output.TeeOutputStream
 */
public class TeePrintWriter extends PrintWriter {

    PrintWriter branch;

    public TeePrintWriter(PrintWriter main, PrintWriter branch) {
        super(main, true);
        this.branch = branch;
    }

    public void write(char buf[], int off, int len) {
        super.write(buf, off, len);
        super.flush();
        branch.write(buf, off, len);
        branch.flush();
    }

    public void write(String s, int off, int len) {
        super.write(s, off, len);
        super.flush();
        branch.write(s, off, len);
        branch.flush();
    }

    public void write(int c) {
        super.write(c);
        super.flush();
        branch.write(c);
        branch.flush();
    }

    public void flush() {
        super.flush();
        branch.flush();
    }
}
